#include <iostream>

namespace myStl {

    template <class T>
    class vector {
    public:
        using iterator = T*;
        using const_iterator = const T*;

        vector(){} = default;
        vector(const vector<T>& v);
        vector<T>& operator=(const vector<T>& v);
        ~vector();
        // 移动构造和移动赋值

        size_t size() {
            return _finish - _start;
        }

        size_t capacity() {
            return _end - _start;
        }

        bool empty() {
            return _start == _finish;
        }

        iterator begin() {
            return _start;
        }

        iterator end() {
            return _finish;
        }

        void reserve(size_t n) {
            // n大于capacity才扩容
            if(n > capacity) {
                // 开辟空间
                size_t oldsize = size();

                T* tmp = new T[n];
                // 不能用memcpy，memcpy是浅拷贝，有内存泄漏的风险
                for(size_t i = 0; i < oldsize; i++) {
                    tmp[i] = _start[i];
                }
                delete _start;

                _start = tmp;
                _finish = tmp + oldsize;
                _end = tmp + n;
            }
        }

    private:
        iterator _start = nullptr;  // 指向首元素字节
        iterator _finish = nullptr; // 指向末尾元素的末尾字节
        iterator _end = nullptr;    //  指向有效空间的末尾字节
    };

};